package logic

import (
	"context"
	"doctor-medicine-system/models"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 登录
func (l *LoginLogic) Login(in *doctorrpc.LoginRequest) (*doctorrpc.LoginResponse, error) {
	// todo: add your logic here and delete this line

	var doctor models.Doctor

	if err := doctor.LoginDoctor(models.DB); err != nil {
		return nil, err
	}

	return &doctorrpc.LoginResponse{
		DoctorId: int64(doctor.ID),
	}, nil
}
